#pragma once

#include "RBTree(copy).h"

namespace ltw
{
    template<class K,class V>
    class map
    {
        struct MapKeyOfT
        {
            const K& operator()(const pair<K,V>& kv)
            {
                return kv.first;
            }
        };
    public:
        typedef typename RBTree<K,pair<K,V>,MapKeyOfT>::Iterator iterator;

        iterator begin()
        {
            return _t.Begin();
        }

        iterator end()
        {
            return _t.End();
        }

        bool insert(const pair<K,V>& kv)
        {
            return _t.Insert(kv);
        }
    private:
        RBTree<K,pair<K,V>,MapKeyOfT> _t;
    };
    void test_map()
    {
        map<int,int> s;
        int a[] = {4,2,6,1,3,5,15,7,16,14};
        for(auto e:a)
        {
            s.insert({e,e});
        }
        for(const auto& e:s)
        {
            cout << e.first << " " << e.second << endl;
        }
        cout << endl;
    }
}